home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / plotting / pcgplots / gptframe.cpp < prev    next >
C/C++ Source or Header  |  1992-04-24  |  12KB  |  383 lines

  1. // GptFrame.cpp
  2. // copyright 1992 Pittsburgh Supercomputing Center
  3. #include "gpt.h"
  4. char FrameWindow::szClass[]       = "gptFrame";
  5. char FrameWindow::szMenu[]        = "gptMenuInit";
  6. char FrameWindow::szAccel[]       = "gptAccel";
  7. HMENU FrameWindow::hMenu          = NULL;
  8. HMENU FrameWindow::hMenuWindow    = NULL;
  9. HANDLE FrameWindow::hAccel = NULL;
  10. // ******************** FrameWindow Class Definitions ************
  11.  
  12. // **** AboutDlgProc
  13. BOOL FAR PASCAL  _export FrameWindow::AboutDlgProc( HWND hDlg, WORD message, WORD wParam,
  14.                      LONG /* lParam */)
  15.     {
  16.     switch (message)
  17.         {
  18.         case WM_INITDIALOG :  return TRUE;
  19.         case WM_COMMAND:
  20.         switch (wParam)
  21.             {
  22.             case IDOK:
  23.             case IDCANCEL:
  24.             EndDialog( hDlg, 0);
  25.             return TRUE;
  26.             }
  27.         break;
  28.         }
  29.     return FALSE;
  30.     }
  31.  
  32. BOOL FAR PASCAL FrameWindow::CloseEnumProc (HWND childhWnd, LONG )
  33.       {
  34.       if (GetWindow (childhWnd, GW_OWNER))         // check for icon title
  35.              return 1 ;
  36.  
  37.       //SendMessage (GetParent (childhWnd), WM_MDIRESTORE, childhWnd, 0L) ;
  38.  
  39.       if (!SendMessage (childhWnd, WM_QUERYENDSESSION, 0, 0L))
  40.              return 1 ;
  41.  
  42.       SendMessage (GetParent (childhWnd), WM_MDIDESTROY, childhWnd, 0L) ;
  43.              return 1 ;
  44.       }
  45.  
  46.  
  47. // *** FrameWindow::WndProc
  48. long FrameWindow::WndProc( HWND hWnd,WORD iMessage, WORD wParam, LONG lParam )
  49.     {
  50.     FileObjectPt FObj;
  51.     HWND hWndChild;
  52.     CLIENTCREATESTRUCT clientcreate;
  53.     MDICREATESTRUCT mdicreate;
  54.     this->iMessage = iMessage;
  55.     this->wParam   = wParam;
  56.     this->lParam   = lParam;
  57.     switch (iMessage)
  58.         {
  59.         case WM_INITMENUPOPUP:
  60.         hWndChild = LOWORD (SendMessage (Appl::hWndClient,
  61.                                                                 WM_MDIGETACTIVE, 0, 0L)) ;
  62.         if (IsWindow (hWndChild))
  63.                  SendMessage (hWndChild, WM_INITMENUPOPUP, wParam, lParam) ;
  64.  
  65.         return 0;
  66.  
  67.  
  68.         case WM_CREATE:
  69.         hWndThis = hWnd;
  70.         Appl::hWndFrame = hWnd;
  71.         clientcreate.hWindowMenu  = hMenuWindow;
  72.         clientcreate.idFirstChild = IDM_FIRSTCHILD;
  73.         // create "client" window
  74.         hWndClient = Appl::hWndClient =
  75.          CreateWindow("MDICLIENT", NULL,    WS_CHILD |WS_CLIPCHILDREN | WS_VISIBLE,
  76.                   0,0,0,0, hWnd,1,Appl::hInstance, (LPSTR)&clientcreate);
  77.         if (!hWndClient) exit(0);
  78.         DoCaption("pcGPlot");
  79.         PostMessage(hWndThis, WM_COMMAND, IDM_FILEARG, 0);
  80.         return 0;
  81.  
  82.         case WM_COMMAND:
  83.         switch (wParam)
  84.             {
  85.             case IDM_FILEARG:        //use filename arg on command line
  86.             LPSTR pt;
  87.             BOOL metFlag = FALSE;
  88.             if (Appl::CmdParam && Appl::CmdParam[0])
  89.                 {
  90.                 // see if filename ends in .met
  91.                 pt = _fstrrchr(Appl::CmdParam, '.');
  92.                 if (pt  && !_fstricmp(pt, ".met")  && !pt[4] ) metFlag = TRUE ;
  93.                 FObj = new FileObject();
  94.                 // Do dialog for opening Disk Metafile or CGM
  95.                 FObj->DialogFileSetup(
  96.                     metFlag?"&Open and Paint Windows Metafile :"
  97.                      :"&Open and Render CGM Binary or Clear Text File :",
  98.                     "",
  99.                     Appl::CmdParam,
  100.                     metFlag?".MET":".CGM",
  101.                     0x4010);
  102.                 if ( FObj->OpenRead( hWndThis) )
  103.                     {
  104.                     if (metFlag)  new WMetaWindow(FObj);
  105.                     else          new CGMWindow(FObj);
  106.                     }
  107.                 else delete FObj;
  108.                 }
  109.  
  110.             return 0;
  111.  
  112.             case IDM_ABOUT:
  113.             DialogBox(Appl::hInstance, "AboutBox", hWnd, lpfnAboutDlgProc);
  114.             return 0;
  115.  
  116.  
  117.             case IDM_CLOSE:          // Close the active window
  118.             hWndChild = LOWORD (SendMessage (hWndClient,
  119.                                                               WM_MDIGETACTIVE, 0,0L));
  120.             if (SendMessage (hWndChild, WM_QUERYENDSESSION, 0, 0L))
  121.                 SendMessage (hWndClient, WM_MDIDESTROY, hWndChild, 0L) ;
  122.             return 0;
  123.  
  124.             case IDM_EXIT:           // Exit the program
  125.             SendMessage (hWnd, WM_CLOSE, 0, 0L) ;
  126.             return 0;
  127.  
  128.             case IDM_OPEN:           // Open a file and window for it
  129.             FObj = new FileObject();
  130.             // Do dialog for opening CGM's
  131.             FObj->DialogFileSetup(
  132.                         "&Open and Render CGM Binary or Clear Text File :",
  133.                         "",
  134.                         "*.CGM",
  135.                         ".CGM",
  136.                         0x4010);
  137.             if ( FObj->OpenRead( hWndThis) )  new CGMWindow(FObj);
  138.             else delete FObj;
  139.             return 0;
  140.  
  141.             case IDM_OPENMETA:   // Open a Windows Metafile and window for it
  142.             FObj = new FileObject();
  143.             // Do dialog for opening Disk Metafile
  144.             FObj->DialogFileSetup(
  145.                         "&Open and Paint Windows Metafile :",
  146.                         "",
  147.                         "*.MET",
  148.                         ".MET",
  149.                         0x4010);
  150.             if ( FObj->OpenRead( hWndThis) )  new WMetaWindow(FObj);
  151.             else delete FObj;
  152.             return 0;
  153.  
  154.             // Messages for arranging windows
  155.             case IDM_TILE:
  156.             SendMessage (hWndClient, WM_MDITILE, 0, 0L) ;
  157.             return 0;
  158.  
  159.             case IDM_CASCADE:
  160.             SendMessage (hWndClient, WM_MDICASCADE, 0, 0L) ;
  161.             return 0;
  162.  
  163.             case IDM_ARRANGE:
  164.             SendMessage (hWndClient, WM_MDIICONARRANGE, 0, 0L) ;
  165.             return 0;
  166.  
  167.             case IDM_CLOSEALL:       // Attempt to close all children
  168.             lpfnCloseEnumProc = MakeProcInstance (
  169.                  (FARPROC)FrameWindow::CloseEnumProc, Appl::hInstance) ;
  170.             EnumChildWindows (hWndClient, lpfnCloseEnumProc, 0L) ;
  171.             FreeProcInstance (lpfnCloseEnumProc) ;
  172.             return 0;
  173.  
  174.             default:            // Pass to active child
  175.             hWndChild = LOWORD (SendMessage (Appl::hWndClient,
  176.                                                                 WM_MDIGETACTIVE, 0, 0L)) ;
  177.             if (IsWindow (hWndChild))
  178.                  SendMessage (hWndChild, WM_COMMAND, wParam, lParam) ;
  179.             break;  // and return defFrameProc
  180.             }
  181.         break;
  182.  
  183.         case WM_QUERYENDSESSION:
  184.         case WM_CLOSE:                     // Attempt to close all children
  185.  
  186.         SendMessage (hWnd, WM_COMMAND, IDM_CLOSEALL, 0L) ;
  187.       // Note if close Icon, this screws up ???
  188.         if (NULL != GetWindow (hWndClient, GW_CHILD)) return 0 ;
  189.         break;
  190.  
  191.  
  192.         case WM_DESTROY :
  193.         PostQuitMessage (0) ;
  194.         return 0;
  195.         }
  196.     return DefFrameProc( hWnd,hWndClient, iMessage, wParam, lParam );
  197.     }
  198. int FrameWindow::MessageLoop( void )
  199.     {
  200.     MSG msg;
  201.  
  202.     while( GetMessage( &msg, NULL, 0, 0 ) )
  203.         {
  204.         if (!TranslateMDISysAccel(hWndClient, &msg) &&
  205.              !TranslateAccelerator(hWndThis, hAccel, &msg) )
  206.             {
  207.             TranslateMessage( &msg );
  208.             DispatchMessage( &msg );
  209.             }
  210.         }
  211.     return msg.wParam;
  212.     }
  213.  
  214.  
  215. // *** FrameWindow constructor
  216. FrameWindow::FrameWindow( void )
  217.     {
  218.         //  strcpy(LocalPath, DefPath);
  219.       //      strcpy(LocalSpec,"*");
  220.         //  strcat(LocalSpec,DefExt);
  221.       //      strcat(LocalExt, DefExt);
  222.     GetDisplayCaps();
  223.     lpfnAboutDlgProc = MakeProcInstance(
  224.             (FARPROC)FrameWindow::AboutDlgProc, Appl::hInstance );
  225.  
  226.      // lpfnFileOpenDlgProc = MakeProcInstance(
  227.      //      (FARPROC)FrameWindow::FileOpenDlgProc, Appl::hInstance) ;
  228.      // lpfnFileSaveDlgProc = MakeProcInstance(
  229.      //    (FARPROC)FrameWindow::FileSaveDlgProc, Appl::hInstance) ;
  230.  
  231.     // Pass 'this' pointer in lpParam of CreateWindow().
  232.     CreateWindow( szClass,
  233.         szClass,
  234.         WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  235.         CW_USEDEFAULT,
  236.         CW_USEDEFAULT,
  237.         CW_USEDEFAULT,
  238.         CW_USEDEFAULT,
  239.         NULL,
  240.         hMenu,
  241.         Appl::hInstance,
  242.         (LPSTR) this );
  243.    // Send WM_CREATE message to window
  244.     if ( ! hWndThis ) exit( FALSE );
  245.     //Appl::hWndClient = GetWindow(hWndThis,Appl::nCmdShow );
  246.     //Appl::hWndFrame  = hWndThis;         //only 1 frame for application
  247.     Show( Appl::nCmdShow );
  248.     Update();
  249.     }
  250.  
  251. // FrameWindow Destructor
  252. FrameWindow::~FrameWindow( void )
  253.     {
  254.    if (lpfnAboutDlgProc)
  255.         FreeProcInstance(lpfnAboutDlgProc);
  256.   //    if (lpfnFileOpenDlgProc)
  257.   //        FreeProcInstance(lpfnFileOpenDlgProc);
  258.   // if (lpfnFileSaveDlgProc)
  259.   //    FreeProcInstance(lpfnFileSaveDlgProc);
  260.    }
  261.  
  262. // *** FrameWindow::Register - static window class register
  263. void FrameWindow::Register( void )
  264.     {
  265.     WNDCLASS wndclass;   // Structure used to register Windows class.
  266.  
  267.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  268.     wndclass.lpfnWndProc   = ::WndProc;     // the global one
  269.     wndclass.cbClsExtra    = 0;
  270.     // Reserve extra bytes for each instance of the window;
  271.     // we will use these bytes to store a pointer to the C++
  272.     // (FrameWindow) object corresponding to the window.
  273.     // the size of a 'this' pointer depends on the memory model.
  274.     wndclass.cbWndExtra  = sizeof( FrameWindow * );
  275.     wndclass.hInstance   = Appl::hInstance;
  276.     wndclass.hIcon       = LoadIcon( Appl::hInstance,szClass );
  277.     wndclass.hCursor     = LoadCursor( NULL, IDC_ARROW );
  278.     wndclass.hbrBackground = COLOR_APPWORKSPACE +1;  // same as client window
  279.     wndclass.lpszMenuName  = NULL;
  280.     wndclass.lpszClassName = szClass;
  281.  
  282.     if ( ! RegisterClass( &wndclass ) ) exit( FALSE );
  283.     }
  284.  
  285. void  FrameWindow::LoadMenu(HANDLE hInstance)
  286.     {
  287.     hMenu = ::LoadMenu( hInstance,szMenu);
  288.     hMenuWindow =
  289.          GetSubMenu( hMenu,INIT_MENU_POS);
  290.     }
  291. void  FrameWindow::LoadAccelerators(HANDLE hInstance)
  292.     {
  293.     hAccel = ::LoadAccelerators( hInstance,szAccel);
  294.     }
  295.  
  296. void FrameWindow::InitMenu( void )
  297.     {
  298.     SendMessage(hWndClient, WM_MDISETMENU,0,
  299.                     MAKELONG( hMenu, hMenuWindow) );
  300.     }
  301.  
  302.  
  303. void FrameWindow::GetDisplayCaps(void)
  304.     {
  305. /* ******
  306.         HDC hdcInfo = CreateIC("DISPLAY", NULL,NULL,NULL);
  307.         int Planes        = GetDeviceCaps(hdcInfo,PLANES);             // =1
  308.         int BitsPixel     = GetDeviceCaps(hdcInfo,BITSPIXEL);          // =8
  309.  
  310.         int NumColors     = GetDeviceCaps(hdcInfo,NUMCOLORS);          // =20
  311.         //Number of entries in the device's color table
  312.  
  313.         int TextCaps      =  GetDeviceCaps(hdcInfo,TEXTCAPS);          // =2004X
  314.             // Bit   Meaning
  315.             // 0    Device can do character output precision.
  316.             // 1    Device can do stroke output precision.
  317.             // 2    ** Device can do stroke clip precision.
  318.             // 3    Device can do 90-degree character rotation.
  319.             // 4    Device can do any character rotation.
  320.             // 5    Device can do scaling independent of X and Y.
  321.             // 6    Device can do doubled character for scaling.
  322.             // 7    Device can do integer multiples for scaling.
  323.             // 8    Device can do any multiples for exact scaling.
  324.             // 9    Device can do double-weight characters.
  325.             // 10    Device can do italicizing.
  326.             // 11    Device can do underlining.
  327.             // 12    Device can do strikeouts.
  328.             // 13    ** Device can do raster fonts.
  329.             // 14    Device can do vector fonts.
  330.             // 15    Reserved. Must be returned zero.
  331.  
  332.         int PolygonalCaps =  GetDeviceCaps(hdcInfo, POLYGONALCAPS);    // =8
  333.                 // Bit   Meaning
  334.                 // 0    Device can do alternate fill polygon.
  335.                 // 1    Device can do rectangle.
  336.                 // 2    Device can do winding number fill polygon.
  337.                 // 3    ** Device can do scanline.
  338.                 // 4    Device can do wide borders.
  339.                 // 5    Device can do styled borders.
  340.                 // 6    Device can do borders that are wide and styled.
  341.                 // 7    Device can do interiors.
  342.  
  343.         int LineCaps      =  GetDeviceCaps(hdcInfo, LINECAPS);         // =22X
  344.             //Bit   Meaning
  345.             // 1    Device can do polyline.
  346.             // 4    Device can do wide lines.
  347.             // 5    Device can do styled lines.
  348.  
  349.         int CurveCaps     =  GetDeviceCaps(hdcInfo, CURVECAPS);        // =0
  350.         // Just Circle
  351.  
  352.         int RasterCaps    =  GetDeviceCaps(hdcInfo, RASTERCAPS);       // =F99X
  353.                 // Raster Capabilities
  354.                 // RC_BITBLT           1                Can do standard BLT.
  355.                 // RC_BITMAP64         8               Device can support >64K bitmap
  356.                 // RC_GDI20_OUTPUT     0x0010       has 2.0 output calls
  357.                 // RC_DI_BITMAP        0x0080       supports DIB to memory
  358.                 // RC_PALETTE          0x0100       supports a palette
  359.                 // RC_DIBTODEV         0x0200       supports DIBitsToDevice
  360.                 // RC_BIGFONT          0x0400       supports >64K fonts
  361.                 // RC_STRETCHBLT       0x0800       supports StretchBlt
  362.  
  363.         // Following valid only if RC_PALETTE on in RASTERCAPS and
  364.         //    Driver Version >= 3.00
  365.         int ColorRes      =  GetDeviceCaps(hdcInfo, COLORRES);         // =18
  366.                         //Actual color resolution of the device in bits per pixel
  367.         int NumReserved   =  GetDeviceCaps(hdcInfo, NUMRESERVED);      // =20
  368.                         // Number of reserved entries in the system palette
  369.         int SizePalette   =  GetDeviceCaps(hdcInfo, SIZEPALETTE);      // =256
  370.                       // Number of entries in the system palette
  371.  
  372.         int ClipCaps      =  GetDeviceCaps(hdcInfo, CLIPCAPS);         // =1
  373.         //1 if the device can clip to a rectangle
  374.  
  375.         int DriverVersion =  GetDeviceCaps(hdcInfo, DRIVERVERSION);    // =300X
  376.         // 3.00
  377.  
  378.         int Technology    =  GetDeviceCaps(hdcInfo, TECHNOLOGY);       // =1
  379.         // raster display
  380.         DeleteDC(hdcInfo);
  381. ************* */
  382.     }
  383.